<template>
    <TopNavComponent />
    <van-dropdown-menu ref="menuRef">
        <van-dropdown-item title="区域" ref="location">
            <div class="list" :active="active" @click="onLocation">
                <h3 :class="[active == 'area' ? 'active' : '']" value="area">区域</h3>
                <h3 :class="[active == 'subway' ? 'active' : '']" value="subway">地铁</h3>
            </div>
            <div class="item">
                <van-cell-group v-if="active == 'area'">
                    <van-cell value="不限" @click="onItem('不限')" />
                    <van-cell value="东城区" @click="onItem('东城区')" />
                    <van-cell value="西城区" @click="onItem('西城区')" />
                    <van-cell value="朝阳区" @click="onItem('朝阳区')" />
                    <van-cell value="通州区" @click="onItem('通州区')" />
                </van-cell-group>
                <van-cell-group v-if="active == 'subway'">
                    <van-cell value="1号线" @click="onItem('1号线')" />
                    <van-cell value="2号线" @click="onItem('2号线')" />
                    <van-cell value="3号线" @click="onItem('3号线')" />
                    <van-cell value="4号线" @click="onItem('4号线')" />
                    <van-cell value="5号线" @click="onItem('5号线')" />
                </van-cell-group>
            </div>
        </van-dropdown-item>
        <van-dropdown-item title="职位" ref="price">
            <van-cell-group>
                <van-cell value="不限" @click="onPrice('不限')" />
                <van-cell value="高级技师" @click="onPrice('高级技师')" />
                <van-cell value="总监" @click="onPrice('总监')" />
                <van-cell value="店长" @click="onPrice('店长')" />
            </van-cell-group>
        </van-dropdown-item>
        <van-dropdown-item title="年龄" ref="type">
            <div class="container">
                <div class="title">年龄选择</div>
                <div class="btn" @click="onType('20')">20-25岁</div>
                <div class="btn" @click="onType('25')">25-30岁</div>
                <div class="btn" @click="onType('30')">30-35岁</div>
            </div>
        </van-dropdown-item>
        <van-dropdown-item title="筛选" ref="more">
            <div class="container">
                <div class="title">评分</div>
                <div :class="[activeBtn1 == 'no' ? 'activeBtn' : '']" class="btn" @click="onMoreSize('no')">不限</div>
                <div :class="[activeBtn1 == '79' ? 'activeBtn' : '']" class="btn" @click="onMoreSize('79')">79分</div>
                <div :class="[activeBtn1 == '34' ? 'activeBtn' : '']" class="btn" @click="onMoreSize('34')">34分</div>
            </div>
            <div class="container">
                <div class="title">单量</div>
                <div :class="[activeBtn2 == 'no' ? 'activeBtn' : '']" class="btn" @click="onMoreFloor('no')">不限</div>
                <div :class="[activeBtn2 == '100' ? 'activeBtn' : '']" class="btn" @click="onMoreFloor('100')">100单+
                </div>
                <div :class="[activeBtn2 == '1000' ? 'activeBtn' : '']" class="btn" @click="onMoreFloor('1000')">1000单+
                </div>
                <div :class="[activeBtn2 == '2000' ? 'activeBtn' : '']" class="btn" @click="onMoreFloor('2000')">2000单+
                </div>
            </div>
            <div class="container btnL">
                <div class="clearBtn" @click="onClearInfo">清空筛选</div>
                <div class="sureBtn" @click="onSure">确定</div>
            </div>
        </van-dropdown-item>
    </van-dropdown-menu>
    <div class="content">
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <div class="person-item" v-for="(item, index) in list" :key="index" @click="onPersonItem(item.id)">
                <img :src="item.image" alt="">
                <div class="person-item-desc">
                    <p>{{ item.name }}</p>
                    <span class="age">工作经验: {{ item.age }}年</span>
                    <span class="price">{{ item.price }}元/月</span>
                    <span class="descs">{{ item.descs }}</span>
                </div>
            </div>
        </van-list>
    </div>
</template>
<script setup lang="ts">
import { ref, reactive } from "vue"
import api from "../../api/index"
import { useRouter } from "vue-router"

import TopNavComponent from '@/components/TopNavComponent.vue'

const router = useRouter()

const menuRef = ref(null)
const location = ref<any>(null);
const price = ref<any>(null)
const type = ref<any>(null)
const more = ref<any>(null)
const active = ref<string>('area')
const activeBtn1 = ref<string>("")
const activeBtn2 = ref<string>("")

interface IList {
    id: number,
    image: any,
    name: string,
    descs: string,
    price: string,
    age:string
}

interface IParams {
    location: string,
    price: string,
    type: string,
    more: string[]
}

const list = ref<IList[]>([]);
const page = ref<number>(1)
const loading = ref(false);
const finished = ref(false);

const params: IParams = reactive({
    location: "不限",
    price: "不限",
    type: "不限",
    more: ["不限", "不限"]
})

const onLocation = (event: any) => {
    active.value = event.target.getAttribute("value")
}

const onItem = (value: string) => {
    location.value.toggle();
    params.location = value
}

const onPrice = (value: string) => {
    price.value.toggle();
    params.price = value
}

const onType = (value: string) => {
    type.value.toggle();
    params.type = value
}

const onMoreSize = (value: string) => {
    activeBtn1.value = value
}

const onMoreFloor = (value: string) => {
    activeBtn2.value = value
    params.more.push(value)
}

const onClearInfo = () => {
    activeBtn1.value = ""
    activeBtn2.value = ""
}

const onSure = () => {
    more.value.toggle();
    console.log(params);
    http()
}

const onLoad = () => {
    http()
};

const http = () => {
    api.getPersonList({
        page: page.value,
        location: params.location,
        price: params.price
    }).then(res => {
        if (res.data.status == 200) {
            page.value++
            list.value = list.value.concat(res.data.data.result)
        }
        // 加载状态结束
        loading.value = false;
        // 数据全部加载完成
        if (res.data.status == 500) {
            finished.value = true;
        }
    })
}

const onPersonItem = (id:number) =>{
    router.push({
        name:"persondetails",
        params:{ id }
    })
}

</script>
<style lang="less" scoped>
.list {
    width: 50%;
    float: left;
    background: #f3f4f5;

    h3 {
        width: 100%;
        font-size: 14px;
        font-weight: 700;
        height: 40px;
        line-height: 40px;
        padding-left: 20px;
        box-sizing: border-box;
    }

    h3.active {
        background: #fff;
    }
}

.item {
    float: left;
    width: 50%;
}

.container {
    background: #fff;
    overflow: hidden;
    clear: both;

    .title {
        padding: 20px;
        box-sizing: border-box;
        font-size: 14px;
    }

    .btn {
        float: left;
        width: 80px;
        height: 30px;
        line-height: 30px;
        background: #f3f4f5;
        margin: 10px;
        text-align: center;
        font-size: 14px;
        margin-top: 0px;
        border-radius: 5px;
    }

    .clearBtn {
        width: 30%;
        height: 40px;
        line-height: 40px;
        text-align: center;
        background: #f3f4f5;
        border-radius: 5px;
        margin: 10px;
    }

    .sureBtn {
        width: 50%;
        height: 40px;
        line-height: 40px;
        text-align: center;
        background: #684886;
        color: #fff;
        border-radius: 5px;
        margin: 10px;
    }
}

.btnL {
    display: flex;
    justify-content: center;
}

.activeBtn {
    background-color: #684886 !important;
    color: #fff;
}

.content {
    padding: 10px;
    background: #fff;

    .person-item {
        display: flex;
        padding: 10px 0;
        border-bottom: 1px solid #f3f4f5;

        img {
            width: 100px;
            border-radius: 5px;
        }

        .person-item-desc {
            padding: 10px;
            box-sizing: border-box;

            p {
                font-size: 15px;
                font-weight: 700;
                margin: 5px 0;
            }

            .age {
                display: block;
                font-size: 14px;
                color: #999;
                margin-bottom: 15px;
            }

            .price {
                display: block;
                font-size: 14px;
                color: #FF4444;
                margin-bottom: 10px;
            }

            .descs {
                font-size: 14px;
                color: #999;
            }
        }
    }
}
</style>
